<template>
  <div>
    <div class="music-list">
      <h3 class="title" v-if="titleFlag">{{ title }}</h3>
      <div class="body-group">
        <div class="body-item" v-for="(item,index) in data" :key="index"
          @click="itemClick(item,index)">
          <!-- <router-link :to="{name: 'songlist', params:{id:item.id}}"> -->
          <img class="item-img" v-lazy="item.picUrl ? item.picUrl : item.coverImgUrl ? item.coverImgUrl :
            item.imgurl ? item.imgurl : item.al.picUrl" >
          <span class="item-span">{{ item.name }}</span>
          <!-- </router-link> -->
        </div>
      </div>
    </div>
  </div>
</template>

<script>

  export default {
    props: {
      data: Array,
      title: String,
      titleFlag:{
        type:Boolean,
        default:true
      }
    },

    inject: ['reload'],
    
    methods:{
      itemClick(item,index){
        console.log(item.id);
        this.$router.push({path:'/songlist/' + item.id});
        this.reload();
      }
    }
  }
</script>

<style scoped>
.music-list {
  width: 100%;
  margin: auto;
  padding-top: 10px;
}

.title {
  height: 40px;
  line-height: 40px;
  margin-left: 3vw;
}

.body-group {
  width: 100%;
  padding: 0 10px;
  box-sizing: border-box;
  display: flex;
  flex-wrap: wrap;
}

.body-item {
  width: 30%;
  display: inline-block;
  margin-bottom: 15px;
  height: auto;
  flex: 0 0 30%;
  font-size: 14px;
  padding: 0 5px 0 5px;
}

.item-img,
.item-span {
  width: 100%;
  border-radius: 5px;
  color: rgb(80, 80, 80);
}

</style>